package main

import (
	"gin-demo01/models"
	"gin-demo01/routers"
	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/redis"
	"github.com/gin-gonic/gin"
	"html/template"
)

func main() {
	r := gin.Default()

	//自定义模版函数  注意要在配置模版文件之前
	r.SetFuncMap(template.FuncMap{
		"UnixToTime": models.UnixToTime,
	})

	//配置模版文件 要在路由上面
	r.LoadHTMLGlob("templates/**/*")

	//配置静态web目录
	r.Static("/static", "./static")

	//配置session中间件
	// 创建基于cookie的存储引擎 secret 参数是用于加密的密钥
	//store := cookie.NewStore([]byte("secret"))
	//r.Use(sessions.Sessions("mysession", store))

	store, _ := redis.NewStore(10, "tcp", "localhost:6379", "", []byte("secret"))
	r.Use(sessions.Sessions("mysession", store))

	routers.RouterInit(r)
	routers.FileRouterInit(r)

	r.Run(":7000")
}
